<?php
include "DBConnection.php";
require_once "./Objects/User.php";

$connection = new Connection(); //connect to the DB

$conf = $_GET['conf'];


//query to get the registered user
$query = "SELECT * 
        FROM workertrack.temp_user
        WHERE confirmation = '$conf';";

$result = $connection->execute_query($query);


if(mysql_num_rows($result)<1) //the code does not exist, meeaning there is no user
{
	echo "user does not exist" or die("user does not exist");
	//header('Location: login_form.php');
 	$connection->close_connection();
}
else
{
	session_start();
	
	$userData = mysql_fetch_array($result, MYSQL_ASSOC);
	$user = new User($userData['w_email'],$userData['pass'],$userData['salt'],time());
	
	
	/*$user->email = $result['w_name'];
	$user->fname = $result['firstname'];
	$user->lname = $result['lastname'];
	$user->id = $result['w_id'];
	$user->password = $result['pass'];
	$user->salt = $result['salt'];*/
	
	//,$result['firstname'],$result['lastname'],$result['w_id'],$result['pass'],$result['salt']
	
	//Insert details to the real worker table
	$insertNew = "INSERT INTO workertrack.worker (w_email,pass,salt)
VALUES ('$user->email','$user->password','$user->salt')";
	
	
	
$connection->execute_query($insertNew);

//delete details from temp_user table
$delete = "DELETE FROM workertrack.temp_user
WHERE confirmation='$conf'";

$connection->execute_query($delete);

//echo "OK";
$connection->close_connection();

 	//get the user logged in
	$_SESSION['login'] = 1;
 	$_SESSION['details'] = $user;
 	
 	
 	echo "You have completed your registration to workertrack!";
 	echo "<br>";
 	echo "press here to go to main";
}






?>